import time
from facility.contro_fn import KeyboardKey,MouseButton,InputController
import math


START_A=(87,147)
START_B=(87,147)
X_OFFSET = 345-START_A[0]
Y_OFFSET = 161-START_A[1]




class Trans:
    def __init__(self,game):
        self.game = game


    def _trigger(self):
        self.game.tap_key(KeyboardKey.KEY_1)
        self.game.up_left()
        time.sleep(0.5)
        self.game.move(100, 20, duration=0.5)
        self.game.click(MouseButton.LEFT)




    def go_to(self,idx):
        self._trigger()
        idx = int(idx)
        row = math.ceil(idx / 3)
        col = idx % 3
        col = col if col != 0 else 3
        if idx <20:
            start = START_A
        else:
            start = START_B

        self.game.move(start[0]+(col-1)*X_OFFSET,start[1]+(row - 1 ) * Y_OFFSET)
        self.game.click(MouseButton.LEFT)


if __name__ == '__main__':
    import sys
    sys.path.append("../")
    from Game import Game
    from facility import Pic
    game = Game('79691793')
    handle = Trans(game)
    handle.go_to(6)

